﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Toad.Application.Forms;
using Weazel.Toad.Application.Items;

#endregion

namespace Weazel.Toad.Application.Actions
{
  public class GotoLineAction : ActionBase
  {
    public GotoLineAction()
    {
      Enabled = false;
      Application.Instance.SelectedItemChanged +=new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
    }


    public override void Execute(object sender, EventArgs e)
    {
      GotoLineForm lineForm = new GotoLineForm();
      if (lineForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        ItemBase item = Application.Instance.SelectedItem;
        System.Diagnostics.Debug.Assert(item is TextFile);
        TextFile textFile = item as TextFile;

        int lineNumber = lineForm.LineNumber;
        textFile.GotoLine(lineNumber);

      }
    }


    void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
      if (e.SelectedItem is TextFile)
        Enabled = true;
      else
        Enabled = false;
    }
  }
}
